package org.altoro.trongeventquery.blocks;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import org.altoro.trongeventquery.transactions.TransactionTriggerEntity;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.CompoundIndexes;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import java.io.Serializable;
import java.util.List;

@Document(collection = "block")
@Getter
@CompoundIndexes(
        {
                @CompoundIndex(name = "block_timeStamp_desc",def = "{'timeStamp':-1}")
        })
public class BlockTriggerEntity implements Serializable {

  private static final long serialVersionUID = -70777625567836430L;

  @Id
  private String id;

  @Field(value = "blockNumber")
  @JsonProperty(value = "blockNumber")
  private long blockNumber;

  @Field(value = "blockHash")
  @JsonProperty(value = "blockHash")
  private String blockHash;

  @Field(value = "parentBlockHash")
  @JsonProperty(value = "parentBlockHash")
  private String parentBlockHash;

  @Field(value = "size")
  @JsonProperty(value = "size")
  private long size;

  @Field(value = "transactionSize")
  @JsonProperty(value = "transactionSize")
  private long transactionSize;

  @Field(value = "witnessesAddress")
  @JsonProperty(value = "witnessAddress")
  private String witnessAddress;

  @Field(value = "totalAmount")
  @JsonProperty(value = "totalAmount")
  private long totalAmount;

  //  @Field(value = " transactionList")
  @JsonProperty(value = "transactionList")
  private List<String> transactionList;

  @Field(value = "timeStamp")
  @JsonProperty(value = "timeStamp")
  private Long timeStamp;

  @Field(value = "triggerName")
  @JsonProperty(value = "triggerName")
  private String triggerName;

  @Field(value = "latestSolidifiedBlockNumber")
  @JsonProperty(value = "latestSolidifiedBlockNumber")
  private long latestSolidifiedBlockNumber;

  @Setter
  private List<TransactionTriggerEntity> transactionTriggerList;


  public BlockTriggerEntity(long blockNumber, String blockHash, String parentBlockHash, long size,  long transactionSize,
      List<String> transactionList, Long timeStamp,String witnessAddress,long totalAmount,
      String triggerName, long latestSolidifiedBlockNumber) {
    this.blockNumber = blockNumber;
    this.blockHash = blockHash;
    this.parentBlockHash = parentBlockHash;
    this.size = size;
    this.transactionSize = transactionSize;
    this.transactionList = transactionList;
    this.timeStamp = timeStamp;
    this.witnessAddress = witnessAddress;
    this.totalAmount = totalAmount;
    this.triggerName = triggerName;
    this.latestSolidifiedBlockNumber = latestSolidifiedBlockNumber;
  }

}
